package com.bdqn.jpathymeleaf.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.jpathymeleaf.service.UserService;
import com.bdqn.jpathymeleaf.pojo.User;

import java.awt.print.Pageable;
import java.util.List;

public class UserServiceImpl implements UserService {
    UserService userService;
    @Override
    public User login(String username, String password) {
        return userService.login(username, password);
    }

    @Override
    public int addUser(User user) {
        return userService.addUser(user);
    }

    @Override
    public int deleteUser(Long usrId) {
        return userService.deleteUser(usrId);
    }

    @Override
    public int updateUser(User user) {
        return userService.updateUser(user);
    }

    @Override
    public User getUer(Long usrId) {
        return userService.getUer(usrId);
    }

    @Override
    public List<User> findAllUsers() {
        return userService.findAllUsers();
    }

    @Override
    public Page<User> findUsers(String username, Long roleId, Pageable pageable) {
        return userService.findUsers(username, roleId, pageable);
    }

   /* @Override
    public Page<User> findUsers(String username, Long roleId, Pageable pageable) {
        Specification<User> specification=new Specification<User>() {
            @Override
            public Predicate toPredicate(Root<User> root, CriteriaQuery<?> criteriaQuery Query, CriteriaBuilder criteriaBuilder) {
                List<Predicate> predicates=new ArrayList<>();
                if(username!=null&&!"".equals(username)){
                    predicates.add(criteriaBuilder.like(root.get("userName"),"%"+username+"%"));
                }
                if(roleId!=null&& roleId.longValue()>0){
                    Role role=new Role();
                    role.setRoleId(roleId);
                    predicates.add(predicates.toArray(new Predicate[predicates.size()]));
                }
            };
            return UserRepository.findAll(Specification,Pageable);
        }
    }*/
}
